package com.ejd.web.vo.genl;

import java.util.List;


import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.IMaterialService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Material;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existMaterial")
@SessionScoped
public class ExistMaterialBean implements java.io.Serializable {

	private SelectItem[] materialItems;

	public SelectItem[] getMaterialItems() {
		return materialItems;
	}

	public void setMaterialItems(SelectItem[] materialItems) {
		this.materialItems = materialItems;
	}
	public ExistMaterialBean() {
		
		IMaterialService<Material,Long> materialService = (IMaterialService<Material,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.MATERIAL_SERVICE_BEAN_NAME);
		materialService.setEntityClass(Material.class);
		materialService.setPKClass(Long.class);
		List<Material> materials = materialService.getAll();
		SelectItem[] tempMaterialItems = new SelectItem[materials.size()];
		if (null != materials && !(materials.isEmpty())) {
			for (int i=0; i< tempMaterialItems.length; i++) {
				Material material = (Material) materials.get(i);
				String materialNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,material.getMaterialName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempMaterialItems[i] = new SelectItem(material.getMaterialCode(),materialNameN18);
			}
		}
		this.setMaterialItems(tempMaterialItems);
	}
}
